<?php
//此为menu权限实验文件
use yii\helpers\Html;
use yii\bootstrap\Nav;
use yii\bootstrap\NavBar;
use yii\widgets\Breadcrumbs;
use app\assets\AppAsset;
use app\modules\backend\rbac\components\MenuHelper;

$i = 0;
foreach (MenuHelper::getAssignedMenu(\Yii::$app->user->id) as $k => $p_menu) {
    echo var_dump($k);
    echo var_dump($p_menu);
    if (!empty($p_menu['items'])) {
        $if_menu = 0;
        //$url = parse_url($_SERVER["REQUEST_URI"]);
        //$url_arr = array_filter(explode("/", $url['path']));
        //$url_items = $item_arr = [];
        //根据URL判断显示
        foreach ($p_menu['items'] as $val) {
            if ($val['url'][0]) {
                $item_arr = array_filter(explode("/", $val['url'][0]));
            }
            $url_items[] = $item_arr[1];
        }
        if (isset($url_arr[1]) && in_array($url_arr[1], $url_items)) {
            $if_menu = 1;
        }
        echo $if_menu == 1 ? 'class="active"' : '';
        echo $p_menu['label'];
        if (!empty($p_menu['items'])) {
            echo $if_menu == 1 ? 'style="display: block;"' : '';
        }
        foreach ($p_menu['items'] as $c_menu) {
            echo Html::a($c_menu['label'], [$c_menu['url'][0], 'id' => 1]);
        }
    } else {
        echo Html::a($p_menu['label'], [$p_menu['url'][0]]);
                }
}
echo "----------------------------------";
foreach (MenuHelper::getAssignedMenu(\Yii::$app->user->id) as $k => $p_menu) {
    $menuItems = array();
    if (!empty($p_menu['items'])) {
        echo "为真";
        echo var_dump($p_menu);
        echo var_dump($p_menu);
        foreach ($p_menu['items'] as $val) {
            if ($val['url'][0]) {
            }
        }

        foreach ($p_menu['items'] as $c_menu) {
        }
    } else {
        echo "为否";
        echo var_dump($p_menu['label']);
        echo var_dump($p_menu['url'][0]);
    }
}
?>

<!-- 以下为基于RBAC的菜单管理 -->
<?php
$menuItems = array();
foreach (MenuHelper::getAssignedMenu(\Yii::$app->user->id) as $k => $p_menu) {

    if (!empty($p_menu['items'])) {
        //多级菜单设置，未完成
        foreach ($p_menu['items'] as $val) {
            if ($val['url'][0]) {
            }
        }

        foreach ($p_menu['items'] as $c_menu) {
        }
    } else {
        //单级菜单
        $menuItems[]=['label' =>$p_menu['label'], 'url' => [$p_menu['url'][0]]];
    }
}
?>
<!-- 以上为基于RBAC的菜单管理 -->